<?php

/**
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 * Copyright (c) 2010 Mr. Ynk: http://www.mrynk.nl
 */

/**
 * @author Michel Ypma: michel@mrynk.nl
 */

class Myto_Config {

    private $conf;

    public function __construct( array $pSettings )
    {
        $this->conf = $pSettings;
        $this->validateSettings();
    }

    public function get( $pSetting )
    {
        if ( array_key_exists( $this->conf['myto'], $pSetting ) )
            return $this->conf['myto'][ $pSetting ];
        throw new Exception( 'Error: reading non existing property "'.$pSetting.'" from Myto_Config' );//notice
    }

    private function validateSettings()
    {
        if ( !isset( $this->conf['myto'] ) )
            throw new Exception( 'Error INI: Missing myto section definition.' );

        if ( !isset( $this->conf['myto']['dir.lib'] ) )
            throw new Exception( 'Error INI: Missing dir.lib definition in myto section.' );
        if ( !is_dir( $this->conf['myto']['dir.lib'] ) )
            throw new Exception( 'Error: dir.lib "'.$this->conf['myto']['dir.lib'].'" is not a directory or doesn\'t exists' );

        if ( !isset( $this->conf['myto']['dir.schema'] ) )
            throw new Exception( 'Error INI: Missing dir.schema definition in myto section.' );
        if ( !is_dir( $this->conf['myto']['dir.schema'] ) )
            throw new Exception( 'Error: dir.schema "'.$this->conf['myto']['dir.schema'].'" is not a directory or doesn\'t exists' );

        if ( !isset( $this->conf['myto']['dir.plugins'] ) )
            throw new Exception( 'Error INI: Missing dir.plugins definition in myto section.' );
        if ( !is_dir( $this->conf['myto']['dir.plugins'] ) )
            throw new Exception( 'Error: dir.plugins "'.$this->conf['myto']['dir.plugins'].'" is not a directory or doesn\'t exists' );
    }

}
?>
